﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Parallel3M.parallel3m.handler;

namespace Parallel3M.parallel3m.framework
{
    class ParallelSingleHandlerTransfer:ParallelTransfer
    {
        public ParallelHandlerContext handlerContext=new ParallelHandlerContext();

        public override ArrayList execute(ParallelPayload payload)
        {
            ArrayList payloads = new ArrayList();

            string handlerid = payload.handlerid;

            //generate the handler by the handleid
            ParallelHandler handler = handlerContext.CreateInstance(handlerid);
            if (handler != null)
            {
                string output_payload_content = handler.handle(payload);

                //build up the output payload
                payload.type = PAYLOADCONSTRANT.TYPE_RESPONSE;
                payload.response = output_payload_content;
                payload.isCompleted = true;
                payloads.Add(payload);
            }
            return payloads;
        }


    }
}
